import java.io.*;
import java.net.*;
import java.util.*;

public class MyEvents {

/*~~~~ ATTRIBUTES ~~~~*/

	public static final String sep = " ~$~ ";
	public static final int intVerbose = 0; // 0 = false, 1 or more = base or more verbose
	protected static Vector<Event> objEvents = new Vector<Event>();


/*~~~~ MAIN ~~~~*/

	public static void main(String[] args) {
		int intParsers = 5;
		String inputFileName = "GroupList.txt";
		String outputFileName = "EventList.txt";
		String inputFileHTML = "template.html";
		String outputFileHTML = "eventi.html";
		String[] strBandInfs = null;
		InputNavigator inputFile = new InputNavigator();
		URLsManager objURLsManager = new URLsManager();
		EventsManager objEventManager = new EventsManager(intParsers);
		ParserThread[] objParsersThreads = new ParserThread[intParsers];
		SorterPostThread objSorterThread = new SorterPostThread(objEventManager);

		/* Sending behavior options to Sorter Thread */
		objSorterThread.setBlnLinearSorting(true);
		objSorterThread.setDoReport(outputFileName);
		objSorterThread.setDoHTML(inputFileHTML, outputFileHTML);

		/* Generating parsers and starting them */ 
		for (int i = 0; i < intParsers; i++) {
			objParsersThreads[i] = new ParserThread(objURLsManager, objEventManager);
			objParsersThreads[i].start();
		}
		objSorterThread.start(); // starts sorter

		/**/System.out.println("\nNow reading from \"" + inputFileName + "\"...\n");/**/

		try {
			inputFile.newStream(inputFileName); //Open input file stream
			while ((strBandInfs = inputFile.readSplitLine("#")) != null) {
				objURLsManager.setStrURLsValue(strBandInfs[0]);
			}
			/* Add a null to "comunicate" URLs are ended up */
			objURLsManager.setStrURLsValue(null);

			inputFile.close(); //Close input file stream

		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
